package com.softlook.mt.server.db.internal;

import java.util.List;
import java.util.Hashtable;
import java.util.Iterator;
import com.softlook.mt.server.db.dto.Deviceevent;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.LinkedList;
import com.softlook.mt.server.db.results.deviceeventmanager.GetMaxDeviceEventIdResult;
import jp.crossfire.framework.database.ISelectResultListener;

public class DeviceEventManagerGetMaxDeviceEventIdListner implements ISelectResultListener {
	public List result = new LinkedList();
	public Hashtable tables = new Hashtable();
	public List deviceeventTmpCache = new LinkedList();
	public  DeviceEventManagerGetMaxDeviceEventIdListner() {
		Hashtable hash = null;
		hash = new Hashtable();
		this.tables.put("deviceevent", hash);
		((Hashtable)this.tables.get("deviceevent")).put("gpsdataid", new Hashtable());
		((Hashtable)this.tables.get("deviceevent")).put("deviceid", new Hashtable());
		((Hashtable)this.tables.get("deviceevent")).put("eventid", new Hashtable());
		((Hashtable)this.tables.get("deviceevent")).put("placeid", new Hashtable());
	}
	public void orMap() {
		Iterator it = this.result.iterator();
		while(it.hasNext()){
			// For each result record
			GetMaxDeviceEventIdResult data = (GetMaxDeviceEventIdResult)it.next();
			Deviceevent deviceevent = (Deviceevent)data.getDeviceevent();
			if(deviceevent != null && !this.deviceeventTmpCache.contains(deviceevent)){
				this.deviceeventTmpCache.add(deviceevent);
			}
		}
		// CREATE FOREIGN KEY VALUE HASH
		// Setup references
	}
	public void getResult(ResultSet result, ResultSetMetaData meta) throws Exception {
		int maxCols = meta.getColumnCount();
		List tableColSettedList= new LinkedList();
		GetMaxDeviceEventIdResult data = new GetMaxDeviceEventIdResult();
		for(int i = 0; i < maxCols; i++){
			if(meta.getColumnName(i+1) == null){continue;}
		
			if(result.getObject(i+1) != null){
				data.put(meta.getColumnName(i+1).toUpperCase(), result.getObject(i+1));
			}
			String columnName = meta.getColumnName(i+1);
			if(Deviceevent.hasColumn(columnName)){
				if(columnName.toUpperCase().equals("deviceeventid".toUpperCase())
		                   && !tableColSettedList.contains("deviceevent.deviceeventid")){
					tableColSettedList.add("deviceevent.deviceeventid");
					if(result.getObject(i+1) != null){
						data.getDeviceeventWithNew().setDeviceeventid(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("gpsdataid".toUpperCase())
		                   && !tableColSettedList.contains("deviceevent.gpsdataid")){
					tableColSettedList.add("deviceevent.gpsdataid");
					if(result.getObject(i+1) != null){
						data.getDeviceeventWithNew().setGpsdataid(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("deviceid".toUpperCase())
		                   && !tableColSettedList.contains("deviceevent.deviceid")){
					tableColSettedList.add("deviceevent.deviceid");
					if(result.getObject(i+1) != null){
						data.getDeviceeventWithNew().setDeviceid(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("eventid".toUpperCase())
		                   && !tableColSettedList.contains("deviceevent.eventid")){
					tableColSettedList.add("deviceevent.eventid");
					if(result.getObject(i+1) != null){
						data.getDeviceeventWithNew().setEventid(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("placeid".toUpperCase())
		                   && !tableColSettedList.contains("deviceevent.placeid")){
					tableColSettedList.add("deviceevent.placeid");
					if(result.getObject(i+1) != null){
						data.getDeviceeventWithNew().setPlaceid(new java.lang.Integer(result.getString(i+1)));
					}
					continue;
				}
				if(columnName.toUpperCase().equals("time".toUpperCase())
		                   && !tableColSettedList.contains("deviceevent.time")){
					tableColSettedList.add("deviceevent.time");
					if(result.getObject(i+1) != null){
						data.getDeviceeventWithNew().setTime(result.getTimestamp(i+1));
					}
					continue;
				}
			}
		}
		tableColSettedList.clear();
		this.result.add(data);
	}
}
